/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
        val(x), next(NULL) {
    }
};
*/
class Solution {
public:
    ListNode* EntryNodeOfLoop(ListNode* pHead) {
        ListNode* fast = pHead;
        ListNode* slow = pHead;
        while(fast != nullptr && fast->next != nullptr){  // 循环条件
            fast = fast->next->next;
            slow = slow->next;
            if(fast == slow){
                ListNode* n1 = pHead;
                ListNode* n2 = slow;
                while(n1 != n2){
                    n1 = n1->next;
                    n2 = n2->next;
                }
                return n1;   // 一定存在入口点
            }      
        }
        return NULL;
    }
};